package com.cp.dao;

import com.cp.repository.Conviction;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


@Mapper
public interface ConvictionMapper {

    @Select("SELECT c.id AS id, c.content AS convictionContent, cc.content AS convictionClassContent FROM conviction c LEFT JOIN conviction_class cc ON c.conviction_class_id = cc.id")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "content", column = "content"),
		    @Result(property = "entry", column = "entry"),
            @Result(property = "convictionClass", column = "conviction_class_id", one = @One(select="com.cp.dao.ConvictionClassMapper.getById"))
    })
    List<Map> getConviction();

    @Select("SELECT * FROM conviction WHERE id = #{id}")
    @Results({
		    @Result(id = true, property = "id", column = "id"),
		    @Result(property = "content", column = "content"),
		    @Result(property = "entry", column = "entry"),
		    @Result(property = "convictionClass", column = "conviction_class_id", one = @One(select="com.cp.dao.ConvictionClassMapper.getById"))
    })
    Conviction getById(Integer id);

	@Select("SELECT * FROM conviction")
	@Results({
			@Result(id = true, property = "id", column = "id"),
			@Result(property = "content", column = "content"),
			@Result(property = "entry", column = "entry"),
			@Result(property = "convictionClass", column = "conviction_class_id", one = @One(select="com.cp.dao.ConvictionClassMapper.getById"))
	})
    List<Conviction> getAll();
}